import { ref } from "vue"
import { defineStore } from "pinia"

const useUserStore = defineStore('user', () => {
  const user = ref(JSON.parse(sessionStorage.getItem('user')) || {})

  const updateUser = (value) => {
    user.value = value
    sessionStorage.setItem('user', JSON.stringify(value))
  }

  const deleteUser = () => {
    user.value = {}
    sessionStorage.removeItem('user')
  }

  return {
    user, updateUser, deleteUser
  }
})

export default useUserStore